package com.ship.contract.bean;

import cn.hutool.core.date.DatePattern;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ship.common.core.base.ContractBaseBean;
import com.ship.common.core.base.Joinable;
import com.ship.common.core.mapping.Label;
import com.ship.common.core.mapping.SearchItem;
import com.ship.common.core.mapping.TableColumn;
import com.ship.common.core.validate.Add;
import com.ship.common.core.validate.Update;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;


import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author 31463
 */
@TableName("con_third_party_measurement")
@Data
public class ConThirdPartyMeasurement extends ContractBaseBean implements Joinable {


    /**
     * 合同名称
     */
    @Label(value = "合同名称")
    @SearchItem
    @TableColumn
    private String contractName;

    /**
     * 执行编号
     */
    @Label(value = "执行编号")
    @SearchItem
    @TableColumn
    private String contractNumber;

    /**
     * 贸易主体(国贸、新贸)
     */
    @Label(value = "合同主体", enumContent = "贸易主体", multiSelect = true)
    @SearchItem
//    @TableColumn
    @NotNull(message = "合同主体不能为空", groups = {Add.class})
    private Integer tradeBody;

    @Label(value = "合同主体", enumContent = "贸易主体", multiSelect = true)
    @TableField(exist = false)
    @TableColumn
    private String tradeBodyStr;

    @TableField(exist = false)
    private String tradeBodyListForSearch;

    /**
     * 甲方
     */
    @Label(value = "甲方")
    @TableColumn
    @NotBlank(message = "甲方不能为空", groups = {Update.class, Add.class})
    @Size(max = 255, message = "甲方长度不能超过255", groups = {Update.class, Add.class})
    private String partyA;

    /**
     * 乙方
     */
    @Label(value = "乙方")
    @SearchItem
    @TableColumn
    @NotBlank(message = "乙方能为空", groups = {Update.class, Add.class})
    @Size(max = 255, message = "乙方长度不能超过255", groups = {Update.class, Add.class})
    private String partyB;

    /**
     * 签订日期
     */
    @Label(value = "签订日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @SearchItem
//    @TableColumn
    @NotNull(message = "签订日期不能为空", groups = {Add.class})
    private Date signingDate;

    @Label(value = "签订日期")
    @TableField(exist = false)
    @TableColumn
    private String signingDateStr;

    @ApiModelProperty(value = "生效日期")
    @Label(value = "生效日期")
    @SearchItem
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
//    @TableColumn
    @NotNull(message = "生效日期不能为空", groups = {Add.class})
    private Date comeIntoForceDate;

    @Label(value = "生效日期")
    @TableField(exist = false)
    @TableColumn
    private String comeIntoForceDateStr;

    /**
     * 合同有效期（单位年）
     */
    @Label(value = "合同有效期")
    @NotNull(message = "合同有效期不能为空", groups = {Add.class})
    private BigDecimal contractValidity;

    /**
     * 合同有效期（单位年）
     */
    @Label(value = "合同有效期")
    @TableField(exist = false)
    @TableColumn
    private String contractValidityStr;

    /**
     * 合同到期日期
     */
    @Label(value = "合同到期日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @SearchItem
//    @TableColumn
    private Date expirationDate;

    @Label(value = "合同到期日期")
    @TableField(exist = false)
    @TableColumn
    private String expirationDateStr;

    /**
     * 合同累计价格
     */
//    @Label(value="合同累计价格")
//    @NotNull(message = "合同累计价格不能为空", groups = {Add.class})
    private BigDecimal totalPrice;

    /**
     * 合同累计价格
     */
//    @Label(value="合同累计价格")
    @TableField(exist = false)
//    @TableColumn
    private String totalPriceStr;

    @Label(value = "乙方提供发票文本")
    @NotNull(message = "乙方提供发票文本不能为空", groups = {Add.class})
    private String partyBSendInvoiceDaysText;

    /**
     * 乙方提供发票时间（天）
     */
    @Label(value = "乙方提供发票时间")
    @NotNull(message = "乙方提供发票时间不能为空", groups = {Add.class})
    private Integer partyBSendInvoiceDays;

    /**
     * 乙方提供发票时间（天）
     */
    @Label(value = "乙方提供发票时间")
    @TableField(exist = false)
    @TableColumn
    private String partyBSendInvoiceDaysStr;

    /**
     * 乙方提供发票时间（天）类型，自然日/工作日
     */
    @Label(value = "乙方提供发票时间类型", enumContent = "乙方提供发票时间类型")
    private Integer partyBSendInvoiceDaysType;

    @ApiModelProperty(value = "合同支付时间文本")
    @Label(value = "合同支付时间文本")
    @NotNull(message = "合同支付时间文本不能为空", groups = {Add.class})
    private String payDaysText;

    /**
     * 支付时间（天）
     */
    @Label(value = "结算时间")
    @NotNull(message = "结算时间不能为空", groups = {Add.class})
    private Integer payDays;

    /**
     *结算时间（天）
     */
//    @Label(value="结算时间")
//    @TableField(exist = false)
//    @TableColumn
//    private String payDaysStr;

    /**
     * 结算时间（天）类型，自然日/工作日
     */
    @Label(value = "结算时间类型", enumContent = "结算时间类型")
    private Integer payDaysType;

    /**
     * 甲方银行账户名称
     */
    @Label(value = "甲方银行账户名称")
    @TableColumn
    private String bankAccountNameA;

    /**
     * 甲方银行名称
     */
    @Label(value = "甲方银行名称")
    @TableColumn
    private String bankNameA;

    /**
     * 甲方银行账户号码
     */
    @Label(value = "甲方银行账户号码")
    @TableColumn
    private String bankAccountNumA;

    /**
     * 甲方SWIFT CODE
     */
    @Label(value = "甲方SWIFT CODE")
    @TableColumn
    private String swiftCodeA;

    /**
     * 甲方银行账户二名称
     */
    @Label(value = "甲方银行账户二名称")
    @TableColumn
    private String bankAccountSecondNameA;

    /**
     * 甲方银行二名称
     */
    @Label(value = "甲方银行二名称")
    @TableColumn
    private String bankNameSecondA;

    /**
     * 甲方银行二账户号码
     */
    @Label(value = "甲方银行二账户号码")
    @TableColumn
    private String bankAccountNumSecondA;

    /**
     * 甲方二SWIFT CODE
     */
    @Label(value = "甲方二SWIFT CODE")
    @TableColumn
    private String swiftCodeSecondA;

    /**
     * 甲方关联账户银行名称
     */
    @Label(value = "甲方关联账户银行名称")
    @TableColumn
    private String relateAccountBankNameA;

    /**
     * 甲方关联银行SWIFT CODE
     */
    @Label(value = "甲方关联银行SWIFT CODE")
    @TableColumn
    private String relateBankSwiftCodeA;

    /**
     * 乙方银行账户名称
     */
    @Label(value = "乙方银行账户名称")
    @TableColumn
    private String bankAccountNameB;

    /**
     * 乙方银行名称
     */
    @Label(value = "乙方银行名称")
    @TableColumn
    private String bankNameB;

    /**
     * 乙方银行账户号码
     */
    @Label(value = "乙方银行账户号码")
    @TableColumn
    private String bankAccountNumB;

    /**
     * 乙方SWIFT CODE
     */
    @Label(value = "乙方SWIFT CODE")
    @TableColumn
    private String swiftCodeB;

    /**
     * 乙方银行账户二名称
     */
    @Label(value = "乙方银行账户二名称")
    @TableColumn
    private String bankAccountSecondNameB;

    /**
     * 乙方银行二名称
     */
    @Label(value = "乙方银行二名称")
    @TableColumn
    private String bankNameSecondB;

    /**
     * 乙方银行二账户号码
     */
    @Label(value = "乙方银行二账户号码")
    @TableColumn
    private String bankAccountNumSecondB;

    /**
     * 乙方二SWIFT CODE
     */
    @Label(value = "乙方二SWIFT CODE")
    @TableColumn
    private String swiftCodeSecondB;

    /**
     * 甲方联系人
     */
    @Label(value = "甲方联系人")
    @TableColumn
    private String contactsA;

    /**
     * 甲方电话
     */
    @Label(value = "甲方电话")
    @TableColumn
    private String phoneA;

    /**
     * 甲方邮箱
     */
    @Label(value = "甲方邮箱")
    @TableColumn
    private String mailboxA;

    /**
     * 乙方联系人
     */
    @Label(value = "乙方联系人")
    @TableColumn
    private String contactsB;

    /**
     * 乙方电话
     */
    @Label(value = "乙方电话")
    @TableColumn
    private String phoneB;

    /**
     * 乙方邮箱
     */
    @Label(value = "乙方邮箱")
    @TableColumn
    private String mailboxB;

    /**
     * 币种
     */
    @Label(value = "币种", enumContent = "币种")
    private Integer currency;

    /**
     * 删除申请
     */
    @Label(value = "删除申请")
    private Integer delApply;

    /**
     * 合同状态
     */
    @Label(value = "合同状态", enumContent = "合同状态")
    private Integer status;

    /**
     * 优秀案例
     */
    @Label(value = "优秀案例", enumContent = "是否是优秀案例")
    private Integer excellent;

    /**
     * 附件地址
     */
    @TableField(exist = false)
    private String filePath;

    /**
     * 合同上传时间
     */
    @Label(value = "合同上传时间")
//    @TableColumn
    @TableField(fill = FieldFill.INSERT)
    private Date createDate;

    @Label(value = "合同上传时间")
    @TableField(exist = false)
    @TableColumn
    private String createDateStr;

    /**
     * 合同创建者
     */
    @Label(value = "合同创建者")
    @TableColumn
    @TableField(fill = FieldFill.INSERT)
    private String createBy;

    /**
     * 预付款时间（单位天）
     */
    @Label(value = "预付款时间")
    private Integer advancePayDays;

    /**
     * 预付款时间类型(工作日，自然日)
     */
    @Label(value = "预付款时间类型", enumContent = "预付款时间类型")
    private Integer advancePayDayType = 1;

    /**
     * 预付款时间（单位天）
     */
    @Label(value = "预付款时间")
    @TableField(exist = false)
    @TableColumn
    private String advancePayDaysStr;

    @Label(value = "删除流程")
    private String deleteProcessInstanceId;

    public String getContractValidityStr() {
        String result = null;
        if (getContractValidity() != null) {
            result = numericFormatting(getContractValidity()) + "年";
        }
        return result;
    }

    public String getPartyBSendInvoiceDaysStr() {
        String result = null;
        if (getPartyBSendInvoiceDays() != null) {
            if (getPartyBSendInvoiceDaysType() == 1) {
                if (StringUtils.isNotBlank(getPartyBSendInvoiceDaysText())) {
                    result = getPartyBSendInvoiceDaysText() + getPartyBSendInvoiceDays() + "工作日";
                } else {
                    result = getPartyBSendInvoiceDays() + "工作日";
                }
            } else if (getAdvancePayDayType() == 2) {
                if (StringUtils.isNotBlank(getPartyBSendInvoiceDaysText())) {
                    result = getPartyBSendInvoiceDaysText() + getPartyBSendInvoiceDays() + "自然日";
                }else{
                    result = getPartyBSendInvoiceDays() + "自然日";
                }
            }
        }
        return result;
    }

    public String getPayDaysStr() {
        String result = null;
        if (getPayDays() != null) {
            if (getPayDaysType() == 1) {
                if (StringUtils.isNotBlank(getPayDaysText())) {
                    result = getPayDaysText() + getPayDays() + "工作日";
                }else{
                    result = getPayDays() + "工作日";
                }
            } else if (getAdvancePayDayType() == 2) {
                if (StringUtils.isNotBlank(getPayDaysText())) {
                    result = getPayDaysText() + getPayDays() + "自然日";
                }else{
                    result = getPayDays() + "自然日";
                }
            }
        }
        return result;
    }

    public String getAdvancePayDaysStr() {
        String result = null;
        if (getAdvancePayDays() != null) {
            if (getPayDaysType() == 1) {
                result = getAdvancePayDays() + "工作日";
            } else if (getPayDaysType() == 2) {
                result = getAdvancePayDays() + "自然日";
            }
        }
        return result;
    }

    public String getTotalPriceStr() {
        String result = null;
        if (getTotalPrice() != null) {
            result = decimalFormat.format(getTotalPrice());
            if (currency == 1) {
                result = "$" + result;
            }
            if (currency == 2) {
                result = "¥" + result;
            }
            if (currency == 3) {
                result = "€" + result;
            }
            if (currency == 4) {
                result = "￡" + result;
            }
            if (currency == 5) {
                result = "C$" + result;
            }
            if (currency == 6) {
                result = "￥" + result;
            }
            if (currency == 7) {
                result = "₹" + result;
            }
            if (currency == 8) {
                result = "p" + result;
            }
            if (currency == 9) {
                result = "₽" + result;
            }
        }
        return result;
    }

    public String getSigningDateStr() {
        String SigningDateStr = null;
        if (null != this.getSigningDate()){
            SigningDateStr = cn.hutool.core.date.DateUtil.format(this.getSigningDate(), DatePattern.NORM_DATE_FORMATTER);
        }
        return SigningDateStr;
    }

    public String getTradeBodyStr(){
        String result = null;
        if (getTradeBody()!=null){
            if (tradeBody == 1){
                result = "国贸";
            }
            if (tradeBody == 2){
                result = "新贸";
            }
        }
        return result;
    }

    public String getComeIntoForceDateStr() {
        String ComeIntoForceDateStr = null;
        if (null != this.getComeIntoForceDate()){
            ComeIntoForceDateStr = cn.hutool.core.date.DateUtil.format(this.getComeIntoForceDate(), DatePattern.NORM_DATE_FORMATTER);
        }
        return ComeIntoForceDateStr;
    }

    public String getExpirationDateStr() {
        String ExpirationDateStr = null;
        if (null != this.getExpirationDate()){
            ExpirationDateStr = cn.hutool.core.date.DateUtil.format(this.getExpirationDate(), DatePattern.NORM_DATE_FORMATTER);
        }
        return ExpirationDateStr;
    }

    public String getCreateDateStr() {
        String createDateStr = null;
        if (null != this.getCreateDate()){
            createDateStr = cn.hutool.core.date.DateUtil.format(this.getCreateDate(), DatePattern.NORM_DATETIME_FORMATTER);
        }
        return createDateStr;
    }

    @Override
    public String getLabel() {
        return null;
    }

    @Override
    public String getValue() {
        return null;
    }
}
